<?php
    // Created By : Noan Babao
    // B.S. Computer Science - De La Salle Canlubang
    // September 28, 2011

    // IN: origin
    // OUT: Tagged by user Main document list 
    // 
    // INCLUDES CONFIGURATION VARIABLES FOR DATABASE ACCESS
    include('../includes/siteConfig.php');
    
    
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
    
    // GET VARIABLES VIA POST METHOD
    $user = $_POST['user'];
    
    // QUERY - GETS ALL DOCUMENTS BASED ON DOCUMENT TYPE
    $query = 
        "
           SELECT MD.mainDocumentId documentId, type, documentName
           FROM Account_Dept_Pos ADP, RouteStep_Dept_Pos RSDP, MainDocument MD, DocumentSetup DS
           WHERE ADP.userId = $user AND RSDP.deptPosId = ADP.deptPosID AND MD.currentStepId = RSDP.stepId AND MD.status= 'Active' AND (action = 'Received' OR action='Pending') AND DS.documentSetupId =MD.documentSetupId
           ORDER BY documentName asc
    
        ";
    
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
    
    // SAVE QUERY RESULTS TO AN ARRAY > $row   
    while ($row = mysql_fetch_array($result)) {
        $jsondata = array();
        $jsondata['documentId'] = $row['documentId'];
        $jsondata['type'] = $row['type'];
        $jsondata['documentName'] = $row['documentName'];
         

        $feed[] = $jsondata;
    }

    echo json_encode($feed);
    
    mysql_free_result($result);
    mysql_close($connect);
?>

